package org.mspring.mlog.web.module.admin.frame;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.mspring.platform.security.SecurityUtils;
import org.mspring.platform.security.entity.TreeItem;
import org.mspring.platform.security.entity.User;
import org.mspring.platform.security.service.TreeItemService;
import org.mspring.platform.web.freemarker.widget.stereotype.Widget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 左侧菜单页面
 *
 * @author Gao Youbo
 * @since 2012-7-16
 */
@Widget
@RequestMapping("/admin")
public class Admin_LeftMenuWidget {

    @Autowired
    private TreeItemService treeItemService;

    @RequestMapping(value = "/leftMenu")
    public String execute(HttpServletRequest request, HttpServletResponse response, Model model) {
        User user = SecurityUtils.getCurrentUser(request);
        List<TreeItem> items = treeItemService.listTreeByUser(user.getId());
        model.addAttribute("items", items);
        return "/admin/frame/leftMenu";
    }
}
